<template>
    <div >
<!--        向上滑动时，应该固定在头部-->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']"
                                 v-for="item in categoryList" :key="item.id"   >
                        {{item.title}}
                    </a>

                </div>
            </div>

        </div>

        <ul class="photo-list">
            <router-link tag="li" to="/photo/info"  v-for="item in list" :key="item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.desc}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
//这里的顶部导航，左右滑动，默认需要js(mui.js)支持
//具体请看http://dev.dcloud.net.cn/mui/ui/#scroll
//mui.js没有兼容js的严格模式，所以，这个地方在使用的时候，会报错，需要取消严格模式(禁用webpack的严格模式)
// cnpm i babel-plugin-transform-strict-mode
// vi .babelrc
// 在plugins节点里添加 transform-strict-mode 插件
// 解决之后，会有相关的警告及错误信息，但不影响使用，如果想屏蔽，可以加touch-action样式，如下样式

import mui from '../../js/mui.min.js'
import { Toast } from 'mint-ui';
    export default {
        data:function () {
            return {
                categoryList:[],
                list:[]
            }
        },
        created(){
          this.getPhotoCategory();
          this.getPhotos();
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods:{
            getPhotoCategory(){
                this.$http.get('/photo-category-list/').then(res => {
                    if (res.body.code == 200){
                        this.categoryList = res.body.data;
                        this.categoryList.unshift({
                            id:0,
                            title:"推荐"
                        })
                        console.log(this.categoryList)
                    }
                    else{
                        Toast(res.body.message)
                    }
                });
            },
            getPhotos(){
                this.$http.get('/get-photos/').then(res => {
                    if (res.body.code == 200){
                        this.list = res.body.data;
                    }
                    else{
                        Toast(res.body.message)
                    }
                });
            }
        }
    }
</script>

<style lang="less">
* {
    touch-action: pan-y;
}



    .photo-list{
        list-style: none;
        margin:0;
        padding: 10px 0;
        padding-bottom: 0;
        li{
            background-color: #ccc;
            text-align: center;
            margin-bottom:10px;
            box-shadow: 0 0 9px #999;
            position: relative;
            img {
                width: 100%;
                vertical-align: middle;
            }
            img[lazy=loading] {
                width: 40px;
                height: 40px;
                margin: auto;
            }
            .info{
                color:white;
                text-align: left;
                position: absolute;
                bottom: 0;
                background-color: rgba(0,0,0,0.4);
                max-height: 84px;
                overflow: hidden;
                .info-title{
                    font-size: 14px;
                }
                .info-body{
                    font-size: 13px;
                }

            }
        }



    }
</style>